﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:m="clr-namespace:MetroWPF.Windows">
    <Style TargetType="{x:Type m:Window}" x:Key="MetroWindow">
        <Setter Property="Foreground" Value="{DynamicResource ApplicationForegroundThemeBrush}" />
        <Setter Property="Background" Value="{DynamicResource ApplicationPageBackgroundThemeBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource WindowBorderThemeBrush}" />
        <Setter Property="TitleBarHeight" Value="{DynamicResource TextControlThemeMinHeight}" />
        <Setter Property="BorderThickness" Value="2" />
        <Setter Property="WindowChrome.WindowChrome">
            <Setter.Value>
                <WindowChrome CaptionHeight="{DynamicResource TextControlThemeMinHeight}" UseAeroCaptionButtons="False" />
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type m:Window}">
                    <Border x:Name="TemplateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Border x:Name="TitleBorder">
                                <Grid MinHeight="{DynamicResource TextControlThemeMinHeight}" Height="{TemplateBinding TitleBarHeight}">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <ContentPresenter x:Name="TitleBar" Content="{TemplateBinding TitleBar}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
                                    <StackPanel Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top" Orientation="Horizontal" WindowChrome.IsHitTestVisibleInChrome="True">
                                        <StackPanel.Resources>
                                            <Style TargetType="{x:Type Button}">
                                                <Setter Property="Background" Value="Transparent" />
                                                <Setter Property="Foreground" Value="{DynamicResource ButtonForegroundThemeBrush}" />
                                                <Setter Property="BorderBrush" Value="Transparent" />
                                                <Setter Property="Padding" Value="10,8,10,8" />
                                                <Setter Property="HorizontalAlignment" Value="Center" />
                                                <Setter Property="VerticalAlignment" Value="Center" />
                                                <Setter Property="FontFamily" Value="Webdings" />
                                                <Setter Property="FontWeight" Value="350" />
                                                <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
                                                <Setter Property="Template">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType="{x:Type Button}">
                                                            <Grid SnapsToDevicePixels="True">
                                                                <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                                                                    <ContentControl x:Name="ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}"  Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                                                    Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                                                </Border>
                                                            </Grid>
                                                            <ControlTemplate.Triggers>
                                                                <Trigger Property="IsEnabled" Value="False">
                                                                    <Setter TargetName="Border" Property="Background" Value="{DynamicResource ButtonDisabledBackgroundThemeBrush}" />
                                                                    <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ButtonDisabledBorderThemeBrush}" />
                                                                    <Setter TargetName="ContentPresenter" Property="Foreground" Value="{DynamicResource ButtonDisabledForegroundThemeBrush}" />
                                                                </Trigger>
                                                                <Trigger Property="IsMouseOver" Value="True">
                                                                    <Setter TargetName="Border" Property="Background" Value="{DynamicResource ButtonPointerOverBackgroundThemeBrush}" />
                                                                    <Setter TargetName="ContentPresenter" Property="Foreground" Value="{DynamicResource ButtonPointerOverForegroundThemeBrush}" />
                                                                </Trigger>
                                                                <Trigger Property="IsPressed" Value="True">
                                                                    <Setter TargetName="Border" Property="Background" Value="{DynamicResource ButtonPressedBackgroundThemeBrush}" />
                                                                    <Setter TargetName="ContentPresenter" Property="Foreground" Value="{DynamicResource ButtonPressedForegroundThemeBrush}" />
                                                                </Trigger>
                                                            </ControlTemplate.Triggers>
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </StackPanel.Resources>
                                        <Button Command="{Binding MinimizeCommand, RelativeSource={RelativeSource Mode=TemplatedParent}}" Content="0" />
                                        <Button x:Name="MaximizeButton" Command="{Binding MaximizeCommand, RelativeSource={RelativeSource Mode=TemplatedParent}}" Content="1" />
                                        <Button Command="{Binding CloseCommand, RelativeSource={RelativeSource Mode=TemplatedParent}}"  Content="r" />
                                    </StackPanel>
                                </Grid>
                            </Border>
                            <ContentPresenter Grid.Row="1"  Margin="{TemplateBinding Padding}" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="WindowState" Value="Maximized">
                            <Setter TargetName="MaximizeButton" Property="Content" Value="2" />
                            <Setter TargetName="TemplateRoot" Property="Padding" Value="8" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>